package com.bussanq.group.alpha.common.util;

import java.util.UUID;

/**
 * @author lizh
 * @date 2017/10/27
 */
public class StrUtils {
	public StrUtils() {
	}

	public static String firstCharToLowerCase(String str) {
		char firstChar = str.charAt(0);
		if (firstChar >= 'A' && firstChar <= 'Z') {
			char[] arr = str.toCharArray();
			arr[0] = (char)(arr[0] + 32);
			return new String(arr);
		} else {
			return str;
		}
	}

	public static String firstCharToUpperCase(String str) {
		char firstChar = str.charAt(0);
		if (firstChar >= 'a' && firstChar <= 'z') {
			char[] arr = str.toCharArray();
			arr[0] = (char)(arr[0] - 32);
			return new String(arr);
		} else {
			return str;
		}
	}

	public static boolean isBlank(String str) {
		if (str == null) {
			return true;
		} else {
			int len = str.length();
			if (len == 0) {
				return true;
			} else {
				int i = 0;

				while(i < len) {
					switch(str.charAt(i)) {
						case '\t':
						case '\n':
						case '\r':
						case ' ':
							++i;
							break;
						default:
							return false;
					}
				}

				return true;
			}
		}
	}

	public static boolean notBlank(String str) {
		return !isBlank(str);
	}

	public static boolean notBlank(String... strings) {
		if (strings != null && strings.length != 0) {
			String[] var1 = strings;
			int var2 = strings.length;

			for(int var3 = 0; var3 < var2; ++var3) {
				String str = var1[var3];
				if (isBlank(str)) {
					return false;
				}
			}

			return true;
		} else {
			return false;
		}
	}

	public static boolean notNull(Object... paras) {
		if (paras == null) {
			return false;
		} else {
			Object[] var1 = paras;
			int var2 = paras.length;

			for(int var3 = 0; var3 < var2; ++var3) {
				Object obj = var1[var3];
				if (obj == null) {
					return false;
				}
			}

			return true;
		}
	}

	public static String toCamelCase(String stringWithUnderline) {
		if (stringWithUnderline.indexOf(95) == -1) {
			return stringWithUnderline;
		} else {
			stringWithUnderline = stringWithUnderline.toLowerCase();
			char[] fromArray = stringWithUnderline.toCharArray();
			char[] toArray = new char[fromArray.length];
			int j = 0;

			for(int i = 0; i < fromArray.length; ++i) {
				if (fromArray[i] == '_') {
					++i;
					if (i < fromArray.length) {
						toArray[j++] = Character.toUpperCase(fromArray[i]);
					}
				} else {
					toArray[j++] = fromArray[i];
				}
			}

			return new String(toArray, 0, j);
		}
	}

	public static String join(String[] stringArray) {
		StringBuilder sb = new StringBuilder();
		String[] var2 = stringArray;
		int var3 = stringArray.length;

		for(int var4 = 0; var4 < var3; ++var4) {
			String s = var2[var4];
			sb.append(s);
		}

		return sb.toString();
	}

	public static String join(String[] stringArray, String separator) {
		StringBuilder sb = new StringBuilder();

		for(int i = 0; i < stringArray.length; ++i) {
			if (i > 0) {
				sb.append(separator);
			}

			sb.append(stringArray[i]);
		}

		return sb.toString();
	}

	public static boolean equals(String a, String b) {
		return a == null ? b == null : a.equals(b);
	}

	public static String getRandomUUID() {
		return UUID.randomUUID().toString().replace("-", "");
	}
}